﻿@model ContosoUniversity.Web.Mvc.Features.Instructor.ViewModels.CreateInstructorWithCoursesViewModel

@{
    ViewBag.Title = "Create";
}

<h2>Create</h2>


@using (Html.BeginForm()) 
{
    @Html.AntiForgeryToken()
    
    <div class="form-horizontal">
        <h4>Instructor</h4>
        <hr />
        @Html.ValidationSummary(true)

        <div class="form-group">
            @Html.LabelFor(model => model.LastName, new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.LastName)
                @Html.ValidationMessageFor(model => model.LastName)
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.FirstMidName, new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.FirstMidName)
                @Html.ValidationMessageFor(model => model.FirstMidName)
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.HireDate, new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.HireDate)
                @Html.ValidationMessageFor(model => model.HireDate)
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.OfficeLocation, new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.OfficeLocation)
                @Html.ValidationMessageFor(model => model.OfficeLocation)
            </div>
        </div>

        <div class="form-group">
            <div class="col-md-offset-2 col-md-10">
                <table>
                    <tr>
                        @{
                            int cnt = 0;
                            List<ContosoUniversity.Web.Mvc.Features.Instructor.AssignedCourseDataViewModel> courses = ViewBag.Courses;

                            foreach (var course in courses)
                            {
                                if (cnt++ % 3 == 0)
                                {
                                    @:</tr><tr>
                                }
                                @:<td>
                                    <input type="checkbox"
                                        name="selectedCourses"
                                        value="@course.CourseID"
                                        @(Html.Raw(course.Assigned ? "checked=\"checked\"" : "")) />
                                        @course.CourseID @:  @course.Title
                                @:</td>
                            }
                            @:</tr>
                        }
                </table>
            </div>
        </div>

        <div class="form-group">
            <div class="col-md-offset-2 col-md-10">
                <input type="submit" value="Create" class="btn btn-default" />
            </div>
        </div>
    </div>
}

<div>
    @Html.ActionLink("Back to List", "Index")
</div>

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}
